<template>
  <div id="wkltByHis">
    <!-- <header class="padding-sm bg-blue">
      <div class="text-bold">报告查询 - {{ hospitalName }}</div>
    </header> -->
    <div class="bodyContent">
      <div class="headerContent padding-left-lg margin-bottom-sm">
        <el-form :inline="true" :model="searchForm">
          <el-form-item label="申请科室" :class='sfxzks == 1 ? "" : "no-edit"'>
            <VxePulldownSelection v-enterNextInput @blur="handleSearch" :url="'/api/sys/findSysOrgDepartmentList'" @confirmClick="dropPullDownConfirm" :tableColumn="[{ field: 'code', title: '编码', width: '60px' }, { field: 'name', title: '名称' }]" :aimKeys="[{ aimKey: 'reqDept', rowKey: 'code' }, { aimKey: 'reqDeptNa', rowKey: 'name' }]" :displayTexts="['name']" :displayTextObj="searchForm.reqDept ? searchForm.reqDept : ''" />
          </el-form-item>
          <el-form-item label="申请医生">
            <VxePulldownSelection ref="employeeSelectRef" :url="'/api/sys/hisEmployee/finAllHisEmployeeList'" @confirmClick="SelectRowClick1" :tableColumn="[
                { title: '编号', field: 'code' },
                { title: '名称', field: 'name', }]" :aimKeys="[
    { formKey: 'code', rowKey: 'code' },
    { formKey: 'name', rowKey: 'name' }
  ]" :displayTexts="['name']" :displayTextObj="searchForm.reqDoctor" />
          </el-form-item>
          <el-form-item label="报告单元">
            <template #default>
              <SelectWorkGroupAllDefaultAll :url="'/api/rptGroup/findRptGroup'" @fatherMethod="getSelectedId" :isShowAll="true" :isClear="true"></SelectWorkGroupAllDefaultAll>
            </template>
          </el-form-item>
          <el-form-item label="条码号" class='no-edit'>
            <el-input v-model="searchForm.reqNo" clearable style="width: 200px" />
          </el-form-item>
          <el-form-item label="病历号">
            <el-input v-model="searchForm.patNo" clearable style="width: 200px" />
          </el-form-item>
          <el-form-item label="姓名" :class='isEditPatNa == 1 ? "" : "no-edit"'>
            <el-input v-model="searchForm.patNa" clearable style="width: 200px" />
          </el-form-item>
          <!-- <el-form-item label="病历号" >
            <el-input v-model="searchForm.patNo" clearable style="width: 200px" />
          </el-form-item>
          <el-form-item label="姓名" >
            <el-input v-model="searchForm.patNa" clearable style="width: 200px" />
          </el-form-item> -->
          <el-form-item label="床号">
            <el-input v-model="searchForm.bedNo" clearable style="width: 200px" />
          </el-form-item>
          <el-form-item label="是否打印">
            <el-select v-model="searchForm.isPrint" placeholder="请选择" size="small" clearable style="width:160px" teleported>
              <el-option label="全部" value="null" />
              <el-option label="是" value="1" />
              <el-option label="否" value="0" />
            </el-select>
          </el-form-item>
          <el-form-item label="检验日期" clearable>
            <el-date-picker v-model="searchForm.sampledaBegin" type="date" placeholder="起始日期" clearable />
            <div>-</div>
            <el-date-picker v-model="searchForm.sampledaEnd" type="date" placeholder="截至日期" clearable />
          </el-form-item>

          <el-form-item>
            <vxe-button content="重置条件" type="text" class="button-blue" @click="resetForm"></vxe-button>
            <vxe-button type="text" content="查询数据" class="button-blue" @click="handleSearch" icon="el-icon-search"></vxe-button>
          </el-form-item>
        </el-form>
        <vxe-button status="primary" class="button-blue" content="预览" @click="previewRpt" icon="vxe-icon-feedback"></vxe-button>
        <vxe-button status="primary" class="button-blue" content="打印" @click="previewPrint" icon="vxe-icon-platform"></vxe-button>
        <vxe-button status="primary" class="button-blue" content="合并打印" @click="ReportCombinePrint" icon="vxe-icon-platform"></vxe-button>
        <vxe-button status="primary" class="button-blue" :content="dzblBtnText !== '' ? dzblBtnText : `电子病历`" @click="getWlEhrName" icon="vxe-icon-file-txt"></vxe-button>
        <vxe-button status="primary" class="button-blue" content="闭环" @click="closedLoopShow" icon="vxe-icon-feedback"></vxe-button>
      </div>
      <div class="tableContent">
        <Splitpanes>
          <Pane size="40">
            <div class="tableBox">
              <vxe-table border class="mytable-scrollbar" :cell-style="cellClassName" show-overflow ref="orgWkltTable" height="auto" :loading="loading" :data="orgWklt" :row-config="{ isHover: true, isCurrent: true, keyField: 'id' }" :sort-config="{ trigger: 'cell' }" :keyboard-config="{ isArrow: true }" :scroll-y="{ enabled: true }" :column-config="{ resizable: true }" @current-change="handleRowClick">
                <vxe-column type="checkbox" width="26"></vxe-column>
                <vxe-column class-name="flag-cell" field="isUrgent" width="16" align="cneter">
                  <template #header>
                    <span style="font-weight: 550" class="text-bold">急</span>
                  </template>
                  <template #default="{ row }">
                    <span v-if="row.isUrgent === 1" class="el-icon-first-aid-kit">
                      <el-icon>
                        <WarnTriangleFilled />
                      </el-icon>
                    </span>
                  </template>
                </vxe-column>
                <vxe-column class-name="flag-cell" field="isPrint" width="16" align="cneter">
                  <template #header>
                    <span style="font-weight: 550" class="text-bold">打</span>
                  </template>
                  <template #default="{ row }">
                    <i v-if="row.isPrint === 1" class="el-icon-printer">
                      <Printer />
                    </i>
                  </template>
                </vxe-column>
                <vxe-column class-name="flag-cell" field="isAutoPrint" width="16" align="cneter">
                  <template #header>
                    <span style="font-weight: 550" class="text-bold">自</span>
                  </template>
                  <template #default="{ row }">
                    <i v-if="row.isAutoPrint === 1" class="el-icon-s-platform">
                      <Monitor />
                    </i>
                  </template>
                </vxe-column>
                <vxe-column class-name="flag-cell" field="isChk" width="16" align="cneter">
                  <template #header>
                    <span style="font-weight: 550" class="text-bold">审</span>
                  </template>
                  <template #default="{ row }">
                    <i v-if="row.isChk === 2" class="el-icon-finished">
                      <SuccessFilled />
                    </i>
                  </template>
                </vxe-column>
                <vxe-column class-name="flag-cell" field="isAlarm" width="16" align="cneter">
                  <template #header>
                    <span style="font-weight: 550" class="text-bold">危</span>
                  </template>
                  <template #default="{ row }">
                    <i v-if="row.isAlarm === 1" class="el-icon-warning">
                      <WarningFilled />
                    </i>
                  </template>
                </vxe-column>

                <vxe-column field="sampleNo" title="标本号" width="40" show-overflow></vxe-column>
                <vxe-column field="sampleda" title="检验日期" width="80" sortable show-overflow></vxe-column>
                <vxe-column field="chkTime" title="报告日期" width="90" sortable show-overflow></vxe-column>
                <vxe-column field="remark1" title="申请号" width="120" show-overflow></vxe-column>
                <vxe-column field="patNa" title="姓名" width="60" sortable show-overflow></vxe-column>
                <vxe-column field="bedNo" title="床号" width="60" sortable show-overflow></vxe-column>
                <vxe-column field="patTypeNa" title="病人类型" width="60" show-overflow></vxe-column>
                <vxe-column field="patNo" title="病历号" width="100" show-overflow></vxe-column>
                <vxe-column field="reqDeptNa" title="科室" width="80" align="center" show-overflow></vxe-column>
                <vxe-column field="sexNa" title="性别" width="30" align="center" show-overflow></vxe-column>
                <vxe-column field="age" title="年龄" width="45" show-overflow></vxe-column>
                <vxe-column field="reqPurpose" title="检验目的" width="100" show-overflow></vxe-column>
                <vxe-column field="sampleTypeNa" title="样本类型" width="60" show-overflow></vxe-column>
                <vxe-column field="reqNo" title="条码号" width="80" show-overflow></vxe-column>
                <vxe-column field="testDoctorNa" title="检验者" width="60" show-overflow></vxe-column>
                <vxe-column field="chkDoctorNa" title="审核者" width="60" show-overflow></vxe-column>
                <vxe-column field="samplingSite" title="采集部位" width="60" show-overflow></vxe-column>
                <vxe-column field="traits" title="标本性状" width="60" show-overflow></vxe-column>
                <vxe-column field="quantity" title="标本量" width="50" show-overflow></vxe-column>
                <vxe-column field="diagnose" title="诊断" width="50" show-overflow></vxe-column>
              </vxe-table>
            </div>
          </Pane>
          <Pane size="60">
            <el-tabs v-model="curSelectRightTab" type="border-card" class="tabsOne" @tab-click="handleClick">
              <el-tab-pane label="检验结果" name="1">
                <div style="height: 100%" v-if="resultType === 1">
                  <vxe-table ref="tableResultRef" :data="resultList" class="mytable-scrollbar" height="auto" :row-config="{ isCurrent: true, isHover: true }" :keyboard-config="{
                      isArrow: true,
                      isTab: true,
                      isEdit: true
                    }" :column-config="{ resizable: true }" resizable show-overflow show-header-overflow :cell-style="calcCellBgColor" :menu-config="rightMenuConfig" @menu-click="contextMenuClickEvent">
                    <vxe-column type="seq" width="30"></vxe-column>
                    <vxe-column field="itemNo" title="项目名称">
                      <template #default="{ row }">
                        <span>{{ row.itemNo + ' ' + row.itemNa }}</span>
                      </template>
                    </vxe-column>
                    <vxe-column field="testResult" title="检验结果"></vxe-column>
                    <vxe-column field="resultFlag" title width="30">
                      <template #default="{ row }">
                        <span class="padding-lr-xs text-df">{{ getResultFlag(row.resultFlag) }}</span>
                        <span class="padding-lr-xs" v-if="row.isAlarm === '1' || row.isAlarm === 1">{{ row.alarmText
                        }}</span>
                      </template>
                    </vxe-column>
                    <vxe-column field="ref" title="参考范围"></vxe-column>
                    <vxe-column field="resultDesc" title="结果说明"></vxe-column>
                    <vxe-column field="instrNa" title="仪器名称"></vxe-column>
                  </vxe-table>
                </div>
                <OrgResultComp ref="orgResultCompRef" :isChildren="true" v-if="resultType === 2" />
              </el-tab-pane>
              <el-tab-pane label="结果回顾" name="2">
                <Splitpanes horizontal>
                  <div style="height: 100%" v-if="resultType === 1">
                    <GeneralReviewArea ref="generalReviewRef" />
                  </div>
                  <div style="height: 100%" v-if="resultType === 2">
                    <div style="height: calc(100% - 40px)">
                      <vxe-table border resizable show-overflow ref="xTableBT3jdjg" height="auto" class="mytable-scrollbar" :data="germDataList">
                        <vxe-column field="rptGroup" title="报告单元" width="160"></vxe-column>
                        <vxe-column field="scheduleDate" title="检验时间" width="120"></vxe-column>
                        <vxe-column field="specTypeName" title="样本类型" width="100"></vxe-column>
                        <vxe-column field="applicationItems" title="检验目的" width="200"></vxe-column>
                        <vxe-column field="isolateNumber" title="编号" width="100"></vxe-column>
                        <vxe-column field="result" title="结果" min-width="160"></vxe-column>
                      </vxe-table>
                    </div>
                  </div>
                </Splitpanes>
              </el-tab-pane>
              <el-tab-pane label="图片" name="3">
                <HisImage ref="imageRef" />
              </el-tab-pane>
              <el-tab-pane label="费用" name="4">
                <HisCost ref="hisCostRef" v-if="resultType === 2" />
                <Cost ref="costRef" v-if="resultType === 1" />
              </el-tab-pane>
              <el-tab-pane label="形态染色结果" name="5" v-if="resultType === 2">
                <ShapeStainingResults />
              </el-tab-pane>
            </el-tabs>
          </Pane>
        </Splitpanes>
      </div>
    </div>
    <!-- 预览报告  [{id:'1',isChecked:true,reportObjectCode:'XXXXX生化报告'},{id:'2',isChecked:false,reportObjectCode:'XXXXX免疫报告'}]-->
    <MultiRptPreview :reportList="reportList" :toggle="isPreviewRpt" :modalTitle="'报告预览'" />
    <!-- 静默打印 -->
    <QuietPrint ref="quietPrintRef" :printParams="printParamsObj" />
    <MergePrint ref="mergequietPrintRef" :printParams="mergePrintParamsObj" />
    <!-- 知识库弹框 -->
    <vxe-modal v-model="showKnowledgeBase" id="showKnowledgeBase" class-name="showKnowledgeBase" width="100%" height="100%" min-width="460" min-height="300" destroy-on-close @hide="showKnowledgeBase = false">
      <template #title>
        <span>知识库</span>
      </template>
      <div style="width: 1000px; height: 100%; margin: 0 auto; background: #fff">
        <KnowledgeBase ref="knowledgeBaseRef"></KnowledgeBase>
      </div>
    </vxe-modal>
    <!-- 闭环展示 -->
    <ClosedLoopComp ref="ClosedLoopCompRef" />
  </div>
</template>
<script setup lang="ts">
import { getCurrentInstance, onMounted, reactive, ref, computed, watch } from 'vue';
import SelectWorkGroupAllDefaultAll from '../lab_bus/components/SelectWorkGroupAllDefaultAll.vue'; //报告单元默认全部引入下拉组件
import OrgResultComp from '../lab_bus/components/OrgResultComp.vue'; //检验结果-细菌
import ShapeStainingResults from '../lab_bus/components/ShapeStainingResults.vue'; //检验结果-细菌
import KnowledgeBase from '@/components/KnowledgeBaseByItem.vue';
import { Pane, Splitpanes } from 'splitpanes';
import { IsEmpty, formatDateTime, sortByField } from '@/utils/common';
import HisImage from '../lab_bus/components/HisImage.vue';
import HisCost from '../lab_bus/components/HisCost.vue';
import Cost from '../lab_bus/components/Cost.vue';
import GeneralReviewArea from '../lab_bus/components/GeneralReviewArea.vue';
import VXETable from 'vxe-table';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import VxePulldownSelection from '@/components/VxePulldownSelection.vue';
import { GetGolbalOptionsAsync, GetLocalOptions, getOptionValueByCodeGlobalOption, getOptionValueByCodeRptGroupOption, GetRptGroupOptionsAsync } from '@/utils/SysOptionsHelper';
import MultiRptPreview from '@/components/MultiRptPreview.vue';
import QuietPrint from '@/components/QuietPrint.vue'; /**静默打印组件 */
import MergePrint from '@/components/MergePrint.vue'; /**合并打印组件 */
import { GetGolbalOptions } from '@/utils/SysOptionsHelper';
import { SysOptions } from '@/stores/sysoptions';
import { wkltByHisRightMenus } from '../lab_bus/components/RptResultUtils.ts';
import ClosedLoopComp from '@/components/ClosedLoopComp.vue';

let { proxy }: any = getCurrentInstance();

const sysoptionObj = SysOptions(); //系统参数状态管理对象
let reportList = reactive([]);
let hisCostRef: any = ref(null); //费用传值
let generalReviewRef: any = ref(null); //历史结果
let costRef: any = ref(null); //费用传值
let imageRef: any = ref(null); //图片ref
let selectWorkGroupRef = ref(null);
const isPreviewRpt = ref(false);
let showKnowledgeBase = ref(false);
let knowledgeBaseRef: any = ref(null);

const quietPrintRef = ref(null); //静默打印组件
const orgResultCompRef = ref(null); //细菌组件
let printParamsObj = ref(null);
let mergePrintParamsObj = ref(null);
let resultType = ref(); //结果类型.1普通/2细菌
let hospitalName = (window as any).hospitalName;
let curSelectRightTab = ref('1');
let reportDay = ref(30);
let orgWkltTable = ref(null); /**检验记录列表对象 */
let germDataList = [
  {
    rptGroup: '细菌MCRSCN',
    scheduleDate: '2023-12-12',
    specTypeName: '大观霉素',
    applicationItems: '肝脏',
    isolateNumber: 'A001',
    result: '无'
  }
];

let form = reactive({});
let currentWork = reactive({}) as any;
// 表单数据
let searchForm = reactive({
  reqDept: '', //申请科室
  reqDoctor: '', //申请医生
  rptGroup: '', //报告单元
  reqNo: '', //条码号
  patNo: '', //病历号
  patId: '', //病人ID
  patNa: '', //姓名
  bedNo: '', //床号
  isPrint: 'null', //是否打印
  sampledaBegin: null,
  sampledaEnd: null,
  isChk: 2
});
let orgWklt = reactive([]); //患者列表
let resultList = reactive([]); //检验结果列表
let patTypeList: any = reactive([]); //字典表：病人类型
let sexList: any = reactive([]); //字典表：性别
let loading = ref(false);
let sfxzks = ref(null);
let pygcShow = ref(false);
let jjbgIsShow = ref(false);

//#region  计算属性
/**病历按钮显示文字(等于-时隐藏) */
let dzblBtnText = computed(() => {
  const a = sysoptionObj.globalOptions.filter((p: any) => p.field === 'blbtntxt');
  if (a && a.length > 0 && a[0] && !IsEmpty(a[0].value)) {
    return IsEmpty(a[0].value) ? '' : a[0].value === '-' ? '' : a[0].value;
  }
  return '';
});
//#endregion

// 方法定义区 =============

let win = window;

let isEditPatNo = ref(0);
let isEditPatNa = ref(0);

function test() {
  if (win.params.isEditPatNo) {
    isEditPatNo.value = 1;
  }
  if (win.params.isEditPatNa) {
    isEditPatNa.value = 1;
  }
}

//#region  生命周期函数
onMounted(async () => {
  await GetGolbalOptionsAsync();
  //his查看报告是否可以选择科室（菏泽三院 游强2025-03-20）
  const xtcs = getOptionValueByCodeGlobalOption('hisckbgsfkyxzks');
  if (xtcs == 1 || xtcs == '1') {
    sfxzks.value = 1;
  }
  //his查看报告是否展示培养观察(镜检)（山亭想展示培养观察）
  const ispygc = getOptionValueByCodeGlobalOption('hisckbgsfzspygc');
  if (ispygc == 1 || ispygc == '1') {
    pygcShow.value = true;
  }
  const noChkShowjjbg = getOptionValueByCodeGlobalOption('hisckbgwshsfdyjjbg');
  if (noChkShowjjbg == 1 || noChkShowjjbg == '1') {
    jjbgIsShow.value = true;
  }
  reportDay.value = getOptionValueByCodeGlobalOption('hisckbgmrrqfw') ? getOptionValueByCodeGlobalOption('hisckbgmrrqfw') : 30;
  searchForm.sampledaBegin = formatDateTime(new Date().valueOf() - (parseInt(reportDay.value) - 1) * 24 * 60 * 60 * 1000, 'yyyy-MM-dd 00:00:00');
  searchForm.sampledaEnd = formatDateTime(new Date().valueOf(), 'yyyy-MM-dd 23:59:59');

  test();
  let hasQuery = false;
  const query = proxy.$route.query as any;
  // if (query.visitNo) {
  //   searchForm.visitNo = query.visitNo;
  //   hasQuery = true;
  // }
  // if (query.patNo) {
  //   searchForm.patId = query.patNo;
  //   hasQuery = true;
  // }
  // if (query.medicalRecNo) {
  //   searchForm.patNo = query.medicalRecNo;
  //   hasQuery = true;
  // }
  // if (query.speccode) {
  //   searchForm.reqNo = query.speccode;
  //   hasQuery = true;
  // }
  // if (query.fullName) {
  //   searchForm.patNa = query.fullName;
  //   hasQuery = true;
  // }
  console.log('hasQuery', IsEmpty((window as any).params.skip1), (window as any).params.skip1);
  if (IsEmpty((window as any).params.skip1) || (window as any).params.skip1 === false) {
    if (query.visitNo || query.visitno) {
      searchForm.visitNo = query.visitNo ? query.visitNo : query.visitno;
      hasQuery = true;
    }
  }
  if (IsEmpty((window as any).params.skip2) || (window as any).params.skip2 === false) {
    if (query.patNo || query.patno) {
      searchForm.patId = query.patNo ? query.patNo : query.patno;
      hasQuery = true;
    }
  }
  if (IsEmpty((window as any).params.skip3) || (window as any).params.skip3 === false) {
    if (query.medicalRecNo || query.medicalrecno) {
      searchForm.patNo = query.medicalRecNo ? query.medicalRecNo : query.medicalrecno;
      hasQuery = true;
    }
  }
  if (IsEmpty((window as any).params.skip4) || (window as any).params.skip4 === false) {
    if (query.specCode || query.speccode) {
      searchForm.reqNo = query.specCode ? query.specCode : query.speccode;
      hasQuery = true;
    }
  }
  if (IsEmpty((window as any).params.skip5) || (window as any).params.skip5 === false) {
    if (query.fullName || query.fullname) {
      searchForm.patNa = query.fullName ? query.fullName : query.fullname;
      hasQuery = true;
    }
  }

  if (query.depCode) {
    const depCodes = [];
    if (typeof query.depCode === 'string') {
      searchForm.reqDept = query.depCode;
    }
    if (typeof query.depCode === 'object') {
      depCodes.push(...query.depCode);
      searchForm.reqDept = depCodes[0];
    }
  }
  /*
    if (hasQuery === true) {
      handleSearch();
    }
  */
  GetGolbalOptions();
  //getWlEhrName();
});
function resetForm() {
  //searchForm.reqDept = ''; //申请科室
  // searchForm.reqDoctor = ''; //申请医生
  // searchForm.rptGroup = ''; //报告单元
  // searchForm.reqNo = ''; //条码号
  // searchForm.patNo = ''; //病历号
  // searchForm.patNa = ''; //姓名
  // searchForm.bedNo = ''; //床号
  searchForm.isPrint = 'null'; //是否打印
  searchForm.sampledaBegin = null;
  searchForm.sampledaEnd = null;
}

// 点击组件表格行(被通知人)
function SelectRowClick1(row) {
  searchForm.reqDoctor = row.row.code;
}

/**下拉选中 */
function dropPullDownConfirm(e) {
  e.aimKeys.forEach((m) => {
    searchForm[m.aimKey] = e.row[m.rowKey];
  });
  handleSearch();
}
// 查询
function handleSearch() {
  resultList.length = 0;
  generalReviewRef.value?.cleanData();
  germDataList.length = 0;
  imageRef.value?.cleanData();
  hisCostRef.value?.cleanData();
  costRef.value?.cleanData();
  getWklt();
}

//获取工作列表
function getSelectedId(selectedRadioId, selectedName) {
  resultList.length = 0;
  generalReviewRef.value?.cleanData();
  germDataList.length = 0;
  imageRef.value?.cleanData();
  hisCostRef.value?.cleanData();
  costRef.value?.cleanData();
  searchForm.rptGroup = selectedRadioId.value;
  if (searchForm.sampledaBegin == null) {
    proxy.$nextTick(() => {
      setTimeout(async () => {
        getWklt();
      }, 500);
    });
  } else {
    getWklt();
  }
}
// 获取报告单列表
function getWklt() {
  VXETable.modal.message({
    id: 'myMsgLoading',
    content: '加载中,请稍后...',
    status: 'loading',
    duration: -1
  });
  orgWklt.length = 0;
  const url = '/lab/maininfo/findLabMaininfoByHis';
  let data: any = Object.assign({}, searchForm);
  data.sampledaBegin = searchForm.sampledaBegin !== null ? formatDateTime(searchForm.sampledaBegin, 'yyyy-MM-dd 00:00:00') : null;
  data.sampledaEnd = searchForm.sampledaEnd !== null ? formatDateTime(searchForm.sampledaEnd, 'yyyy-MM-dd 23:59:59') : null;
  data.isPrint = searchForm.isPrint === 'null' ? null : searchForm.isPrint;

  proxy.$http
    .post(url, data)
    .then((res: any) => {
      if (res.data && res.data.length > 0) {
        orgWklt.push(...res.data);
        handleRowClick({ row: res.data[0] });
      } else if (res.data && res.data.length == 0 && resultType.value === 2) {
        orgResultCompRef.value.clearData();
      }
      VXETable.modal.close('myMsgLoading');
    })
    .catch((err) => {
      VXETable.modal.close('myMsgLoading');
      VxeMessage(err, VxeNotifyType.error);
    });
}

//rowClick
function handleRowClick({ row }) {
  proxy.$refs.orgWkltTable.setCurrentRow(row);
  Object.assign(form, row);
  Object.assign(currentWork, row);
  imageRef.value.getImageData(form);
  if (IsEmpty(row)) {
    resultList.length = 0;
    return;
  }
  proxy.$emit('RowClick', row);
  if (row.businessType === '20') {
    //判断是细菌的报告单元
    resultType.value = 2; //普通的
    proxy.$nextTick(() => {
      //进行组件查询
      row.pygcShow = pygcShow.value;
      orgResultCompRef.value.initPage(row); //调用菜单组件方法
    });
  } else {
    resultType.value = 1;
    commonReuslt(row.id);
    proxy.$nextTick(() => {
      //generalReviewRef.value?.getResultReview(row);
      if (generalReviewRef.value) {
        if (!IsEmpty(curSelectRightTab.value) && `${curSelectRightTab.value}` === '2') {
          generalReviewRef.value?.getResultReview(row);
        }
      }
      costRef.value?.getreqDetail({ reqNo: row.reqNo });
    });
  }
}

function commonReuslt(id: any) {
  resultList.length = 0;
  const url = '/lab/maininfo/findRptResultByLabMaininfo';
  proxy.$http
    .get(url, { params: { id: id } })
    .then((res: any) => {
      //resultList.push(...res.data);
      resultList.push(...sortByField(res.data, 'displayOrder', 'asc'));

      loading.value = false;
    })
    .catch((err) => {
      loading.value = false;
      VxeMessage(err, VxeNotifyType.error);
    });
}

function getResultFlag(val) {
  const a = getOptionValueByCodeRptGroupOption('zjmaccsxs');
  if (a === '1' || a === 1) {
    if (val === 'H') {
      const b = getOptionValueByCodeRptGroupOption('pgjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '↑';
    }
    if (val === 'L') {
      const b = getOptionValueByCodeRptGroupOption('pdjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '↓';
    }
    if (val === 'P') {
      const b = getOptionValueByCodeRptGroupOption('yxjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '+';
    }
    if (val === 'Q') {
      const b = getOptionValueByCodeRptGroupOption('ryxjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '±';
    }
    if (val === 'M') {
      const b = getOptionValueByCodeRptGroupOption('zcjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '';
    }
    if (val === 'E') {
      const b = getOptionValueByCodeRptGroupOption('cwjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '×';
    }
    if (val === 'N') {
      const b = getOptionValueByCodeRptGroupOption('nxjgbz');
      if (!IsEmpty(b)) {
        return b;
      }
      return '√';
    }
  }
  if (val === 'H') {
    return '↑';
  }
  if (val === 'L') {
    return '↓';
  }
  if (val === 'P') {
    return '+';
  }
  if (val === 'Q') {
    return '±';
  }
  if (val === 'N') {
    return '√';
  }
  if (val === 'E') {
    return '×';
  }
  if (val === 'M') {
    return '';
  }
  return '';
}
/**
 * 单元格背景颜色
 *【1】是否启用系统选项颜色配置  encolorsetting
 *【2】偏高结果颜色  hresultcolor
 *【3】偏低结果颜色  lresultcolor
 *【4】阳性结果颜色  presultcolor
 *【5】正常结果颜色  mresultcolor
 *【6】弱阳性结果颜包  qresultcolor
 *【7】错误结果颜色  errresultcolor
 *【8】阴性结果颜色  nresultcolor
 *【9】结果标志颜色显示方式 jgbzysxsfs (0:背景色  1:文字颜色)
 */
function calcCellBgColor({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex }) {
  /**偏高【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'H' && column && column.field === 'resultFlag') {
    //查询系统选项偏高显示颜色   背景色还是文字颜色
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('hresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#ff0000' };
  }
  /**偏高【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'H' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('hresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#ff0000', color: '#fff' };
  }

  /**偏低【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'L' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('lresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#0035ff' };
  }
  /**偏低【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'L' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('lresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#0035ff', color: '#fff' };
  }

  /**阳性【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'P' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('presultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#0035ff' };
  }
  /**阳性【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'P' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('presultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#0035ff', color: '#fff' };
  }

  /**弱阳性【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'Q' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('qresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#0035ee' };
  }
  /**弱阳性【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'Q' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('qresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#0035ee', color: '#fff' };
  }

  /**错误【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'E' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('errresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#800000' };
  }
  /**错误【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'E' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('errresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { background: '#800000', color: '#fff' };
  }

  /**正常【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'M' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('mresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#000' };
  }
  /**正常【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'M' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('mresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { color: '#000' };
  }

  /**阴性【标志】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'N' && column && column.field === 'resultFlag') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const b = getOptionValueByCodeRptGroupOption('jgbzysxsfs');
      const c = getOptionValueByCodeGlobalOption('nresultcolor');
      if (b === '0' || b === 0) {
        if (!IsEmpty(c)) {
          return { background: c, color: '#fff' };
        }
      }
      if (b === '1' || b === 1) {
        if (!IsEmpty(c)) {
          return { color: c };
        }
      }
    }
    return { color: '#000' };
  }
  /**阴性【结果】 */
  if (row && row.resultFlag && !IsEmpty(row.resultFlag) && row.resultFlag === 'N' && column && column.field === 'testResult') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    if (a === '1' || a === 1) {
      const c = getOptionValueByCodeGlobalOption('nresultcolor');
      if (!IsEmpty(c)) {
        return { background: c, color: '#fff' };
      }
    }
    return { color: '#000' };
  }

  /**危急值 颜色 */
  if (row && !IsEmpty(row.isAlarm) && row.isAlarm === 1 && column && column.field === 'itemNo') {
    const a = getOptionValueByCodeGlobalOption('encolorsetting');
    const b = getOptionValueByCodeGlobalOption('isalarmcolor');
    const d = getOptionValueByCodeGlobalOption('wjzyssfxswbjys'); /**危急值颜色显示是否为背景颜色 wjzyssfxswbjys */
    if (a === 1 || a === '1') {
      if (!IsEmpty(b)) {
        if (d && (d === '1' || d === 1)) {
          return { background: b, color: '#fff' };
        } else {
          return { color: b };
        }
      }
    }
  }
}
//预览
function previewRpt() {
  isPreviewRpt.value = false;
  const arrSelects = orgWkltTable.value?.getCheckboxRecords();
  reportList.length = 0;
  if (IsEmpty(form)) {
    VxeMessage('预览失败', VxeNotifyType.error);
    return;
  }
  //山亭-镜检未审核也能进行预览和打印报告
  if (jjbgIsShow.value) {
    proxy.$http
      //.post('/lab/maininfo/previewRpt', form)
      .post('/lab/maininfo/viewRptBatch', arrSelects && arrSelects.length > 0 ? arrSelects : [form])
      .then((res: any) => {
        Object.assign(reportList, res.data);
        isPreviewRpt.value = true;
      })
      .catch((err: any) => {
        VxeMessage('预览失败', VxeNotifyType.error);
      });
  } else {
    if (form.isChk != 2) {
      VxeMessage('未审核不能预览', VxeNotifyType.warning);
      return;
    }
    if (!arrSelects || arrSelects.length > 0) {
      arrSelects.forEach((item) => {
        if (!item.isChk || item.isChk < 2) {
          VxeMessage('存在未审核记录,不允许预览', VxeNotifyType.warning);
          return;
        }
      });
    }
    //染色节点走特有的处理
    if (form.bacFlowNode == 'STAINING') {
      bacPreviewRpt(arrSelects, form);
      return;
    }

    proxy.$http
      //.post('/lab/maininfo/previewRpt', form)
      .post('/lab/maininfo/viewRptBatch', arrSelects && arrSelects.length > 0 ? arrSelects : [form])
      .then((res: any) => {
        Object.assign(reportList, res.data);
        isPreviewRpt.value = true;
      })
      .catch((err: any) => {
        VxeMessage('预览失败', VxeNotifyType.error);
      });
  }
}
//微生物-染色结果打印的时候走特殊处理
function bacPreviewRpt(arrSelects, form) {
  isPreviewRpt.value = false;
  //先根据路由的URL获取对应的报表信息
  let url = `/api/pubReport/getReportByBusFormCode?code=007`;
  proxy.$http
    .get(url)
    .then((res: any) => {
      const reportId = res.data.id;
      reportList.length = 0;
      if (arrSelects.length > 0) {
        arrSelects.forEach((item) => {
          const data = {
            id: item.id,
            reportTemplateName: '染色报告.rdlx',
            reportId: reportId
          };
          reportList.push(data);
        });
      } else {
        const data = {
          id: form.id,
          reportTemplateName: '染色报告.rdlx',
          reportId: reportId
        };
        reportList.push(data);
      }
      isPreviewRpt.value = true;
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}
//打印
async function previewPrint() {
  let data = [];
  const rowList = proxy.$refs.orgWkltTable.getCheckboxRecords(true);
  if (jjbgIsShow.value) {
    if (rowList.length === 0) {
      if (currentWork || IsEmpty(currentWork.id)) {
        VxeMessage('请选择一条数据', VxeNotifyType.warning);
        return;
      }
      data.push(currentWork);
    } else {
      rowList.forEach((item) => {
        data.push(item);
      });

      const reportRes: any = await new Promise((resolve, reject) => {
        const url = '/lab/maininfo/printRptBatch';
        proxy.$http
          .post(url, data)
          .then((res: any) => {
            let arr = [];
            res.data.forEach((e) => {
              arr.push({ ReportName: e.reportId, ReportParameters: [{ Name: 'Id', Value: e.id }], PdfPrinterSetting: { PdfPrinterCopies: 1 } });
            });
            printParamsObj.value = arr; //[{ ReportName: '1759924571139497986', ReportParameters: [{ Name: 'Id', Value: '123' }], PdfPrinterSetting: { PdfPrinterCopies: 1 } }]; // { id: new Date().valueOf(), params: ['123', '345', '567'] };
          })
          .catch((err: any) => {
            VxeMessage('打印失败', VxeNotifyType.error);
          });
      });
    }
  } else {
    if (rowList.length === 0) {
      if (currentWork || IsEmpty(currentWork.id)) {
        VxeMessage('请选择一条数据', VxeNotifyType.warning);
        return;
      }
      if (!currentWork.isChk || currentWork.isChk < 2) {
        VxeMessage('存在未审核记录,不允许打印', VxeNotifyType.warning);
        return;
      }
      data.push(currentWork);
    } else {
      let isNoReviewed = false;
      rowList.forEach((item) => {
        data.push(item);
        if (!item.isChk || item.isChk < 2) {
          isNoReviewed = true;
        }
      });
      if (isNoReviewed) {
        VxeMessage('存在未审核记录,不允许打印', VxeNotifyType.warning);
        return;
      }
    }
    //染色节点走特有的处理
    if (rowList[0].bacFlowNode == 'STAINING') {
      bacPreviewPrint(rowList);
      return;
    }
    const reportRes: any = await new Promise((resolve, reject) => {
      const url = '/lab/maininfo/printRptBatch';
      proxy.$http
        .post(url, data)
        .then((res: any) => {
          let arr = [];
          res.data.forEach((e) => {
            arr.push({ ReportName: e.reportId, ReportParameters: [{ Name: 'Id', Value: e.id }], PdfPrinterSetting: { PdfPrinterCopies: 1 } });
          });
          printParamsObj.value = arr; //[{ ReportName: '1759924571139497986', ReportParameters: [{ Name: 'Id', Value: '123' }], PdfPrinterSetting: { PdfPrinterCopies: 1 } }]; // { id: new Date().valueOf(), params: ['123', '345', '567'] };
        })
        .catch((err: any) => {
          VxeMessage('打印失败', VxeNotifyType.error);
        });
    });
  }
}
//微生物-染色结果打印的时候走特殊处理
async function bacPreviewPrint(rowList) {
  const reportRes: any = await new Promise((resolve, reject) => {
    let url = `/api/pubReport/getReportByBusFormCode?code=007`;
    proxy.$http
      .get(url)
      .then((res: any) => {
        let arr = [];
        if (res && res.status && res.status.code === 1 && res.data && !IsEmpty(res.data.id)) {
          rowList.forEach((item) => {
            arr.push({ ReportName: res.data.id, ReportParameters: [{ Name: 'Id', Value: item.id }], PdfPrinterSetting: { PdfPrinterCopies: 1 } });
          });
        } else {
          proxy.$alert('查无容器条码模板', '提示');
        }
        printParamsObj.value = arr; //[{ ReportName: '1759924571139497986', ReportParameters: [{ Name: 'Id', Value: '123' }], PdfPrinterSetting: { PdfPrinterCopies: 1 } }]; // { id: new Date().valueOf(), params: ['123', '345', '567'] };
      })
      .catch((err: any) => {
        VxeMessage('打印失败', VxeNotifyType.error);
      });
  });
}

//合并打印
async function ReportCombinePrint() {
  let labMaininfoId = [];
  const rowList = proxy.$refs.orgWkltTable.getCheckboxRecords(true);
  if (jjbgIsShow.value) {
    if (rowList.length === 0) {
      if (currentWork || IsEmpty(currentWork.id)) {
        VxeMessage('请选择一条数据', VxeNotifyType.warning);
        return;
      }
      labMaininfoId.push(currentWork.id);
    } else {
      rowList.forEach((item) => {
        labMaininfoId.push(item.id);
      });
    }
    const keyData = [];
    const groupedItems = rowList.reduce((acc, item) => {
      const key = `${item.patNo}-${item.reqDept}`; // 创建组合键
      keyData.push(key);
      if (!acc[key]) {
        acc[key] = []; // 如果键不存在，初始化数组
      }
      acc[key].push(item); // 将当前项添加到对应的数组中
      return acc;
    }, {});

    let keys = Array.from(new Set(keyData));

    let timeOut = 0;
    keys.forEach(async (item, index) => {
      let lengthids = 1;
      const dataIds = groupedItems[item].map((p) => p.id);
      let data = {
        labMaininfoIds: dataIds
      };
      console.log('当前次数报告量' + dataIds.length);
      if (index == 0) {
        timeOut = 0;
      } else {
        lengthids = groupedItems[keys[index - 1]].map((p) => p.id).length;
        if (lengthids < 6) {
          timeOut += 10000;
        }
        if (lengthids >= 6) {
          timeOut += 17000;
        }
      }
      setTimeout(() => {
        console.log('开始执行' + lengthids + '时间' + new Date().getSeconds());
        proxy.$http
          .post('/lab/maininfo/labMainInfoMergePrint', data)
          .then((res: any) => {
            if (res && res.status && res.status.code !== 1) {
              VxeMessage(res.status.msg, VxeNotifyType.error);
            } else if (res && res.status && res.status.code === 1 && res.data && res.data.length > 0) {
              ReportCombinedPrinted(res);
            } else {
              VxeMessage('请求错误', VxeNotifyType.error);
            }
          })
          .catch((err) => {});
      }, timeOut); // 每个元素之间有1秒的延时
    });
  } else {
    if (rowList.length === 0) {
      if (currentWork || IsEmpty(currentWork.id)) {
        VxeMessage('请选择一条数据', VxeNotifyType.warning);
        return;
      }
      if (!currentWork.isChk || currentWork.isChk < 2) {
        VxeMessage('存在未审核记录,不允许打印', VxeNotifyType.warning);
        return;
      }
      labMaininfoId.push(currentWork.id);
    } else {
      let isNoReviewed = false;
      rowList.forEach((item) => {
        console.log(item);
        labMaininfoId.push(item.id);
        if (!item.isChk || item.isChk < 2) {
          isNoReviewed = true;
        }
      });
      if (isNoReviewed) {
        VxeMessage('存在未审核记录,不允许打印', VxeNotifyType.warning);
        return;
      }
    }
    const keyData = [];
    const groupedItems = rowList.reduce((acc, item) => {
      const key = `${item.patNo}-${item.reqDept}`; // 创建组合键
      keyData.push(key);
      if (!acc[key]) {
        acc[key] = []; // 如果键不存在，初始化数组
      }
      acc[key].push(item); // 将当前项添加到对应的数组中
      return acc;
    }, {});

    let keys = Array.from(new Set(keyData));

    let timeOut = 0;
    keys.forEach(async (item, index) => {
      let lengthids = 1;
      const dataIds = groupedItems[item].map((p) => p.id);
      let data = {
        labMaininfoIds: dataIds
      };
      console.log('当前次数报告量' + dataIds.length);
      if (index == 0) {
        timeOut = 0;
      } else {
        lengthids = groupedItems[keys[index - 1]].map((p) => p.id).length;
        if (lengthids < 6) {
          timeOut += 10000;
        }
        if (lengthids >= 6) {
          timeOut += 17000;
        }
      }
      setTimeout(() => {
        console.log('执行' + lengthids + '时间' + new Date().getSeconds());
        proxy.$http
          .post('/lab/maininfo/labMainInfoMergePrint', data)
          .then((res: any) => {
            if (res && res.status && res.status.code !== 1) {
              VxeMessage(res.status.msg, VxeNotifyType.error);
            } else if (res && res.status && res.status.code === 1 && res.data && res.data.length > 0) {
              ReportCombinedPrinted(res);
            } else {
              VxeMessage('请求错误', VxeNotifyType.error);
            }
          })
          .catch((err) => {});
      }, timeOut); // 每个元素之间有1秒的延时
    });
  }
}

async function ReportCombinedPrinted(res) {
  const reportRes: any = await new Promise((resolve, reject) => {
    let arr = [];
    res.data.forEach((e) => {
      arr.push({
        reportName: e.rptTemplateCode,
        reportParameters: [{ name: 'Id', value: e.id }],
        pageUnit: e.pageUnit
      });
    });
    mergePrintParamsObj.value = arr; //[{ ReportName: '1759924571139497986', ReportParameters: [{ Name: 'Id', Value: '123' }], PdfPrinterSetting: { PdfPrinterCopies: 1 } }]; // { id: new Date().valueOf(), params: ['123', '345', '567'] };
  });
}
function getWlEhrName() {
  const url = '/api/sys/hisEmployee/getInterfaceData';
  const params = {
    url: '/EHR/getEHRByIdNo',
    code: 'GET_EHR',
    patNo: form.patNo,
    reqNo: form.reqNo,
    idNo: form.idNo
  };
  proxy.$http
    .get(url, { params: params })
    .then((res: any) => {
      if (!IsEmpty(JSON.parse(res.data).data)) {
        window.open(JSON.parse(res.data).data);
      }
    })
    .catch((err: any) => {
      VxeMessage(`获取地址失败,请联系管理员`, VxeNotifyType.error);
    });
}
/**tab页签点击事件 */
function handleClick(e) {
  if (generalReviewRef.value && !IsEmpty(e.index) && `${e.index}` === '2') {
    generalReviewRef.value?.getResultReview(form);
  }
}
/**单元格样式
 *【1】是否启用系统选项颜色配置  encolorsetting
 *【1】急背景色  isurgentcolor
 *【2】打背景色  isprintcolor
 *【3】自助机打印背景色  isautoprintcolor
 *【4】审核背景色  ischkcolor
 *【5】危急值背景色  isalarmcolor
 *【6】门诊类型病人列表颜色  mzpattypecolor
 *【7】住院类型病人列表颜色  zypattypecolor
 *【8】急诊类型病人列表颜色  jzpattypecolor
 *【9】体检类型病人列表颜色  tjpattypecolor
 *【10】其他类型病人列表颜色  qtpattypecolor
 */
function cellClassName({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex }) {
  let patTypeColor = '';

  if (column.property === 'isUrgent') {
    if (row.isUrgent === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isurgentcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff', padding: '0', margin: '0' };
        }
      }
      return { background: '#FF0000', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isChk') {
    if (row.isChk === 2) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('ischkcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#008000', color: '#fff' };
    } else if (row.isChk === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('ischkcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#00FF00', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isAlarm') {
    if (row.isAlarm === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isalarmcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#FF9900', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isAutoPrint') {
    if (row.isAutoPrint === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isautoprintcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#800080', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  if (column.property === 'isPrint') {
    if (row.isPrint === 1) {
      const a = getOptionValueByCodeGlobalOption('encolorsetting');
      const b = getOptionValueByCodeGlobalOption('isprintcolor');
      if (a === 1 || a === '1') {
        if (!IsEmpty(b)) {
          return { background: b, color: '#fff' };
        }
      }
      return { background: '#000080', color: '#fff' };
    } else {
      return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
    }
  }
  return !IsEmpty(patTypeColor) ? { color: patTypeColor } : {};
}

const tableResultRef = ref(null);
const rightMenuConfig = ref(
  wkltByHisRightMenus(proxy, ({ options, column, row }) => {
    if (tableResultRef.value) {
      tableResultRef.value?.setCurrentRow(row);
      tableResultRef.value?.focus();
      //handleRowClick({ row });
    }
    const isDisabled = !column;
    options.forEach((list: any) => {
      list.forEach((item: any) => {
        console.log('item======>>>>>>>>>>', item);
        item.disabled = isDisabled;
      });
    });
  })
);
/**右键菜单事件
 * @param menu 菜单对象
 * @param row 右键行对象
 * @param column 右键列对象
 */
function contextMenuClickEvent({ menu, row, column }) {
  switch (menu.code) {
    case 'knowledgeBase':
      getKnowledgeBaseData(row);
    default:
      break;
  }
}
// 获取知识库数据
function getKnowledgeBaseData(row) {
  showKnowledgeBase.value = true;
  proxy.$nextTick(() => {
    knowledgeBaseRef.value?.findKnowledgeBaseByAnsList(row);
  });
}
let ClosedLoopCompRef = ref(null); /**闭环展示弹窗对象 */

function closedLoopShow() {
  const arrSelects = orgWkltTable.value?.getCheckboxRecords();
  if (arrSelects.length > 0) {
    const sltObj = arrSelects[0];
    console.log(sltObj);
    if (sltObj && !IsEmpty(sltObj.reqNo)) {
      ClosedLoopCompRef.value?.initPage(sltObj);
    }
  }
}
</script>
<style lang="scss" scoped>
#wkltByHis {
  width: 100%;
  height: 100%;

  .bodyContent {
    height: calc(100% - 20px - 39px);

    // 附加按钮间距
    .button-blue,
    .button-red {
      margin: 0 5px 0 0;
    }

    // 表格左侧小边距
    :deep(.vxe-cell) {
      padding-left: 5px;
    }

    .headerContent {
      background-color: #fff;
      box-sizing: border-box;
      padding: 10px 0 0 15px;
    }

    .tableContent {
      height: calc(100% - 70px - 20px - 20px);
      background-color: #fff;

      .tableBox {
        height: calc(100%);
      }

      .tabsOne {
        height: 100%;

        :deep(.el-tabs__content) {
          padding: 5px;
          height: calc(100% - 49px);

          .el-tab-pane {
            height: 100%;

            .el-tabs {
              height: 100%;
            }
          }
        }
      }
    }
  }
}

:deep(.flag-cell) {
  .vxe-cell {
    padding: 0 2px !important;
  }
}

.no-edit {
  user-select: none;
  /* 禁止选择文本 */
  pointer-events: none;
  /* 禁止所有鼠标事件 */
  cursor: none;
  opacity: 0.7;
}
</style>
